<script src="{{ getAssets }}js/amazeui.datatables.min.js?v={{ assets_version }}"></script>
<script>
	var tables = $('#dataTables').DataTable({
		"sAjaxSource" : "{{ urlfor "FollowupController.DataGrid"}}"
		,"bLengthChange": false
		,"fnServerData" : function(sSource, aoData, fnCallback) {
			var params = checkQueryTableData(aoData)
			params.Archives = {{.m.Id}};
			$.post(sSource, JSON.stringify(params),function(resp) {
				fnCallback(resp);
			},'json')
		}
		,columns: [
			{"mDataProp" : "Id", "bSortable": false}
			,{"data" : "CreatedAt","bSortable": false, render:function(data, type, full, meta) {
				return timetrans(data);		
			}}
			,{"mDataProp" : "CreatedBy", "bSortable": false}
			,{"mDataProp" : "Message", "bSortable": false}
			,{   
				"mDataProp": "Action", 
				"bSortable": false, 
				"sWidth":"6%",
				"render": function ( data, type, full, meta ) { 
					btns = '<a href="javascript:;" class="am-btn am-btn-danger am-btn-xs" onclick="deleteFollowup('+ full.Id +')">删除</a>';
					return btns;  
				}  
			 } 
		]
		,"aLengthMenu":[20, 50, 100, 200]
		,'bLengthChange': true
		,"serverSide": true
		,"bPaginate" : true
		,"bFilter" : false	//是否启动过滤、搜索功能 
		,"bInfo" : true //是否显示页脚信息，DataTables插件左下角显示记录数
		,"bProcessing" : true //DataTables载入数据时，是否显示‘进度’提示  
		  
	});
	
	$("#searchsubmit").bind("click", function () { //点击按钮 触发table重新请求服务器
		$("#dataTables").dataTable().fnDraw(false);
	});
	
	function dialogReback() {
		$("#dataTables").dataTable().fnDraw(false);
	}
	
	var archid = 0;
	
	$('#addFollowup').click(function(){
		archid = $(this).data('id');
		if(archid == 0) {
			layer.msg("没有档案信息，请刷新页面");
			return false;	
		}
		layer.open({
			type: 2
			, title: '添加随访'
			, shade: 0.2
			, id: 'viewOptometry_dialog'
			, area: ['600px', '350px']
			, content: ['{{ urlfor "FollowupController.Add"}}']
			, anim: 1 //动画类型
		});
		return false;	
	}); 
	
	function deleteFollowup(id) {
		layer.confirm('确定要删除所选记录吗？删除后不可恢复！', function(index){
			$.post('{{ urlfor "FollowupController.Delete"}}', {id:id}, function(res){
				if(res.code == 1) {
					layer.msg(res.msg)
				} else {
					tables.ajax.reload();
				}
				layer.close(index);
			}, 'json');
		});
	}
</script>